package com.exam.controller;
import com.exam.entity.QuestionRule;
import com.exam.service.QuestionRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
//考题规则的增删改查
@RestController
@RequestMapping("/api/question-rules")
public class QuestionRuleController {

    @Autowired
    private QuestionRuleService questionRuleService;

    @PostMapping
    public QuestionRule addQuestionRule(@RequestBody QuestionRule questionRule) {
        return questionRuleService.addQuestionRule(questionRule);
    }

    @GetMapping("/{id}")
    public QuestionRule getQuestionRuleById(@PathVariable Long id) {
        return questionRuleService.getQuestionRuleById(id);
    }

    @PutMapping("/{id}")
    public QuestionRule updateQuestionRule(@PathVariable Long id, @RequestBody QuestionRule questionRule) {
        return questionRuleService.updateQuestionRule(id, questionRule);
    }

    @DeleteMapping("/{id}")
    public void deleteQuestionRule(@PathVariable Long id) {
        questionRuleService.deleteQuestionRule(id);
    }

    @GetMapping("/paged")
    public Page<QuestionRule> getAllQuestionRulesPaged(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        Pageable pageable = PageRequest.of(page, size);
        return questionRuleService.getAllQuestionRules(pageable);
    }
}